public class CommonRecursionMethod
{
    public List<Id> RoleIdList{get;set;}
    
    public CommonRecursionMethod()
    {
        RoleIdList=new List<Id>();
    }
    public List<Id> getASMBelowRoleId()
    {
        List<Id> inputIdList=new List<Id>();
      //  List<Id> outputIdList=new List<Id>();
        List<Id> returnIdList=new List<Id>();
        User user=[select Id,Name,UserRoleId,Title__c,FunctionDepartment__c from User where Id=:UserInfo.getUserId()];
        if(user.Title__c=='Area/District Sales Manager' || user.Title__c=='Sales Supervisor')
        {
           getId(user.UserRoleId,inputIdList);
           returnIdList.add(user.id);//加入自己
           if(inputIdList.size()>0)
           {
              for(user u:[select id from User where UserRoleId in:inputIdList])
                  returnIdList.add(u.id);
            }
            return returnIdList;
        }
        return null;
    }
    public void getId(Id uId,List<Id> idList)
    {
        for(UserRole ur:[Select Id, Name, ParentRoleId from UserRole where ParentRoleId=:uId])
        {
            idList.add(ur.Id);
            getId(ur.Id,idList);
        }  
    }
    //传入TSR ID 找出上级ASM的ID
    public void getASMId(string inputId,string outputId)
    {
        for(User u:[select id,Title__c,ManagerId from User where id=:inputId])
        {
            if(u.Title__c=='Area/District Sales Manager')
            {
                outputId=u.id;
             }
            else
                getASMId(u.ManagerId,outputId);
        }
    }
    
     //传入ID 找出RSM的ID
    public void getRSMId(string inputId,List<id> outputIdList)
    {
        for(User u:[select id,Title__c,ManagerId from User where id=:inputId])
        {
            if(u.Title__c=='Regional Sales Manager')
                outputIdList.add(u.id);
            else
                getRSMId(u.ManagerId,outputIdList);
        }
    }
}